//翻牌
const Common=require('../../util/common');
let drawConfig=[
    {type:301,count:1,weight:10},
    {type:302,count:1,weight:10},
    {type:303,count:1,weight:10},
    {type:304,count:1,weight:10},
    {type:305,count:1,weight:10},
    {type:401,count:1,weight:10},
    {type:402,count:1,weight:10},
    {type:403,count:1,weight:10},
    {type:404,count:1,weight:10},
    {type:405,count:1,weight:10}
];

let mongoose = require('mongoose');
let schema = new mongoose.Schema({
    drawArray:{
        type:Array,
        default:[]
    }
},{versionKey:false});

schema.methods={
    //进行一次翻牌
    async luckDraw(options){
        let drawArray=[].concat(this.drawArray);
        let draw=Common.weightRandom(drawArray);
        console.log(drawArray);
        let index=drawArray.findIndex(item=>{return item.type===draw.type;});
        if(!draw){
            throw new Error('没有剩余的牌可以翻了');
        }
        drawArray.splice(index,1);
        this.drawArray=drawArray;
        options.self.getGoods([draw]);
        return draw;
    },
    //获取翻牌初始信息
    async getDraw(options){
        let skin=Common.weightRandom(drawConfig);
        this.drawArray=[
            {type:1,count:100,weight:30},
            {type:2,count:388,weight:30},
            {type:101,count:3,weight:30},
            skin
        ];
        return this.drawArray;
    }
};

module.exports = schema;